function $(selector){
	var result = document.querySelectorAll(selector);
	if(result.length === 1){
		return result[0]
	}
	return result;
}
function bindEvent(nodeList,eventType,fn){
	for(var i = 0; i < nodeList.length;i++){
		nodeList[i][eventType] = fn
	}
}
function getRandomColor(){
	var arr = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];
	var result = "#";
	for(var i = 0; i < 6;i++){
		var index = Math.floor(Math.random() * 16)
		result = result + arr[index];
	}
	return result;
}

Array.prototype.has = function(query){
	let isHas = false;
	// 指向 实例对象 : 数组
	this.forEach(item=>{
		if(item === query){
			isHas = true;
		}
	})
	return isHas;
}

NodeList.prototype.bind = function(eventType,fn){
	if(typeof eventType === "function" && fn === undefined){
		fn = eventType;
		eventType = "onclick";
	}
	this.forEach(item=>{
		item[eventType] = fn;
	})
	return this;
}

HTMLCollection.prototype.bind = function(eventType,fn){
	if(typeof eventType === "function" && fn === undefined){
		fn = eventType;
		eventType = "onclick";
	}
	for(let i = 0; i < this.length;i++){
		this[i][eventType]=fn;
	}
	return this;
}

// 相当于为所有元素节点扩展方法
HTMLElement.prototype.fadeOut = function(speed=0.05,callback){
	if(speed === "slow"){speed = 0.02};
	if(speed === "fast"){speed = 0.08};
	if(typeof speed === "function"){
		callback = speed;
		speed = 0.05;
	}
	this.style.opacity = 1;
	let fadeOut = setInterval(()=>{
		let o = parseFloat(this.style.opacity);
		if(o <= 0){
			this.style.opacity = 0;
			this.style.display = "none";
			clearInterval(fadeOut)
			callback && typeof callback ===  "function" ? callback() : ""
			return;
		}
		this.style.opacity = o - speed;
	},16)
}
HTMLElement.prototype.fadeIn = function(speed=0.05,callback){
	if(speed === "slow"){speed = 0.02};
	if(speed === "fast"){speed = 0.08};
	if(typeof speed === "function"){
		callback = speed;
		speed = 0.05;
	}
	this.style.opacity = 0;
	this.style.display = "block";
	let fadeOut = setInterval(()=>{
		let o = parseFloat(this.style.opacity);
		if(o >= 1){
			this.style.opacity = 1 ;
			clearInterval(fadeOut)
			callback && typeof callback ===  "function" ? callback() : ""
			return;
		}
		this.style.opacity = o + speed;
	},16)
}
